package com.leetcode.LC;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LC268 {
    public int missingNumber(int[] nums) {
        List<Integer> resultList = new ArrayList<>();
        for (int num : nums) {
            resultList.add(num);
        }
        for (int i = 0; i <= nums.length; i++) {
            if (!resultList.contains(i)) {
                return i;
            }
        }
        return -1;
    }

    public int missingNumber2(int[] nums) {
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++) {
            if (i!=nums[i]){
                return i;
            }
        }
        return nums.length;
    }

    public static void main(String[] args) {
        System.out.println(new LC268().missingNumber2(new int[]{9, 6, 4, 2, 3, 5, 7, 0, 1}));
    }
}
